package com.gdones.wms.bus.warehouse.controller;


import com.gdones.common.core.annotations.MySysLog;
import com.gdones.common.core.annotations.MySysLogOpration;
import com.gdones.common.core.dto.MyPageBand;
import com.gdones.common.core.dto.MyPager;
import com.gdones.common.core.dto.MyResult;
import com.gdones.wms.bus.warehouse.dto.WmsWarehouse;
import com.gdones.wms.bus.warehouse.service.IWmsWarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author GaoJingBo
 * @since 2023-05-06
 */
@RestController
@RequestMapping("/warehouse")
@Slf4j
@Api(tags = "仓库管理")
public class WmsWarehouseController {

    @Resource(name = "wmsWarehouseServiceImpl")
    private IWmsWarehouseService wmsWarehouseService;

    @GetMapping("/pages")
    @ApiOperation("仓库管理-分页信息")
    @MySysLog(modelName="仓库管理",methodDesc = "分页信息",methodType = MySysLogOpration.GET)
    public MyResult pages(WmsWarehouse dto, MyPageBand pager){

        log.debug("--仓库管理：分页信息");
        MyResult result = new MyResult();

        try {

            MyPager<WmsWarehouse> res = wmsWarehouseService.pages(dto,pager);

            result.setMsg("查询成功！");
            result.setData(res);

        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("仓库管理-分页查询-异常！");
        }

        return result;
    }

    @GetMapping("/list")
    @ApiOperation("仓库管理-列表信息（不分页）")
    @MySysLog(modelName="仓库管理",methodDesc = "列表信息（不分页）",methodType = MySysLogOpration.GET)
    public MyResult pages(WmsWarehouse dto){

        log.debug("--仓库管理：列表信息（不分页）");
        MyResult result = new MyResult();

        try {

            List<WmsWarehouse> res = wmsWarehouseService.mylist(dto);

            result.setMsg("查询成功！");
            result.setData(res);

        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("仓库管理-列表信息（不分页）-异常！");
        }

        return result;
    }

    @PostMapping("/add")
    @ApiOperation("仓库管理-添加")
    @MySysLog(modelName="仓库管理",methodDesc = "添加",methodType = MySysLogOpration.POST)
    public MyResult add(@RequestBody WmsWarehouse dto){

        log.debug("--仓库管理：添加");
        MyResult result = new MyResult();

        try {

            result = wmsWarehouseService.add(dto);

        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("仓库管理-添加-异常！");
        }

        return result;
    }

    @PutMapping("/update")
    @ApiOperation("仓库管理-修改")
    @MySysLog(modelName="仓库管理",methodDesc = "修改",methodType = MySysLogOpration.PUT)
    public MyResult update(@RequestBody WmsWarehouse dto){

        log.debug("--仓库管理：修改");
        MyResult result = new MyResult();

        try {

            result = wmsWarehouseService.update(dto);

        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("仓库管理-修改-异常！");
        }

        return result;
    }

    @DeleteMapping("/deletes")
    @ApiOperation("仓库管理-删除")
    @MySysLog(modelName="仓库管理",methodDesc = "删除",methodType = MySysLogOpration.DELETE)
    public MyResult deletes(String ids){

        log.debug("--仓库管理：删除");
        MyResult result = new MyResult();

        try {

            result = wmsWarehouseService.deletes(ids);

        }catch (Exception e){
            e.printStackTrace();
            result.setCode("9999");
            result.setMsg("仓库管理-删除-异常！");
        }

        return result;
    }

}
